const express = require('express');
const fs = require('fs');
const path = require('path')
const session = require('express-session');/*引入会话变量*/

let app = express();

app.use(session({
    secret: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890$_', // 建议使用 128 个字符的随机字符串
    cookie: { maxAge: 30 * 60 * 1000 }, //cookie生存周期30分钟
    resave: true,  //cookie之间的请求规则,假设每次登陆，就算会话存在也            重新保存一次
    saveUninitialized: true //强制保存未初始化的会话到存储器
})); 


app.use(express.static(path.join(__dirname,'public')))

app.use(express.urlencoded({extended:false}));
app.set("view engine",'ejs')
app.set("views",path.join(__dirname,"views"))

app.use("/admin",require("./router/admin"))
app.use("/article",require("./router/article"))
app.use("/user",require("./router/user"))
app.use("/message",require("./router/message"))
app.use("/power",require("./router/power"))

app.get("/",(req,res)=>{

    res.render('index')
})



app.get('*', function(req, res){
    res.render('404')
});





process.on('uncaughtException', function (err) {
    fs.writeFileSync(path.join(__dirname,'/log/'+(new Date().getTime()))+'.log',err.stack)
});



app.listen(80,()=>{
    console.log('请访问：http://localhost');
})